<template id="GoToBack">
  <div class="GoToBack" ref="GoToBack">
    <div class="option" v-if="!isPhone">
      <md-button class="backBtn" @click="back"
        ><img :src="backIcon" class="backIcon" /> 返回</md-button
      >
    </div>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
import { getWidth } from "@/utils";
export default {
  name: "goToBack",
  components: {},
  // 定义属性
  data() {
    return {
      isPhone: false,
      currentWidth: "",
      backIcon: require("@/assets/images/mail/backArr.png"),
    };
  },
  props: {
    path: {
      type: String,
    },
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    back() {
      if (this.path) {
        this.$router.push(this.path);
      } else {
        this.$router.go(-1);
      }
    },
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.currentWidth = getWidth();
    if (this.currentWidth <= 768) {
      this.isPhone = true;
    } else {
      this.isPhone = false;
    }
    let that = this;
    window.onresize = function() {
      if (that.$refs.GoToBack) {
        that.currentWidth = getWidth();
        if (that.currentWidth <= 768) {
          that.isPhone = true;
        } else {
          that.isPhone = false;
        }
      }
    };
  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {}, // 如果页面有keep-alive缓存功能，这个函数会触发
};
</script>

<style lang="less" scoped>
.GoToBack {
  .option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    margin-bottom: 27px;
    .backBtn {
      margin: 0;
      width: 104px;
      height: 30px;
      background-image: url("../../../../../assets/images/mail/backBg.png");
      background-size: 100% 100%;
      background-color: transparent !important;
      color: #ffffff !important;
      border: none;
      box-shadow: unset;
      .backIcon {
        width: 20px;
        height: 6px;
        margin-right: 10px;
      }
      /deep/.md-ripple {
        padding: 0 !important;
        /deep/.md-button-content {
          font-size: 12px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          display: flex;
          align-items: center;
          justify-content: center;
        }
      }
    }
  }
}
@media screen and (max-width: 768px) {
  .GoToBack {
    display: none;
  }
}
</style>
